package com.yida.gwj.report.controller;

import com.yida.common.core.enums.UserStatus;
import com.yida.common.core.utils.DateUtils;
import com.yida.common.core.utils.StringUtils;
import com.yida.common.core.utils.poi.ExcelUtil;
import com.yida.common.core.web.controller.BaseController;
import com.yida.common.core.web.domain.AjaxResult;
import com.yida.common.core.web.page.TableDataInfo;
import com.yida.common.log.annotation.Log;
import com.yida.common.log.enums.BusinessType;
import com.yida.common.security.annotation.RequiresPermissions;
import com.yida.gwj.common.utils.GwjConvertUtil;
import com.yida.gwj.report.domain.dto.GwjFinanceMoneyDTO;
import com.yida.gwj.report.domain.request.GwjFinanceMoneyQueryRequest;
import com.yida.gwj.report.domain.request.GwjReportFinanceMoneyQueryRequest;
import com.yida.gwj.report.domain.vo.GwjFinanceMoneyExcelVO;
import com.yida.gwj.report.service.IGwjFinanceMoneyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author lqq
 * @date 2023-03-07
 */
@RestController
@RequestMapping("/money")
@Api(tags = "缴存金额收入总帐明细")
public class GwjFinanceMoneyController extends BaseController {

	@Resource
	private IGwjFinanceMoneyService financeMoneyService;

	@GetMapping("/list")
	@RequiresPermissions("gwj:report:money:list")
	@ApiOperation("查询缴存金额收入总帐明细列表（需分页）")
	public TableDataInfo list(GwjFinanceMoneyQueryRequest request) {
		startPage();
		//查询未删除的
		request.setDelFlag(UserStatus.OK.getCode());
		List<GwjFinanceMoneyDTO> list = financeMoneyService.selectFinanceMoneyDetailList(request);
		return getDataTable(list);
	}

	@PostMapping("/export")
	@RequiresPermissions("gwj:report:money:export")
	@Log(title = "缴存金额收入总帐明细", businessType = BusinessType.EXPORT, systemName = "gwj")
	@ApiOperation("导出缴存金额收入总帐明细列表")
	public void export(HttpServletResponse response, @RequestBody GwjFinanceMoneyQueryRequest request) {
		//查询未删除的
		request.setDelFlag(UserStatus.OK.getCode());
		List<GwjFinanceMoneyDTO> list = financeMoneyService.selectFinanceMoneyDetailList(request);
		ExcelUtil<GwjFinanceMoneyExcelVO> util = new ExcelUtil<>(GwjFinanceMoneyExcelVO.class);
		util.exportExcel(response, GwjConvertUtil.convertList(list, GwjFinanceMoneyExcelVO.class), "分户旧数据_" + DateUtils.dateTimeNow());
	}

	@GetMapping("/year")
	@RequiresPermissions("gwj:report:money:year")
	@ApiOperation("查询缴存金额收入总帐明细列表-年报")
	public AjaxResult getYearReport(GwjReportFinanceMoneyQueryRequest request) {
		return AjaxResult.success(financeMoneyService.getYearReport(request));
	}

	@GetMapping("/month")
	@RequiresPermissions("gwj:report:money:month")
	@ApiOperation("查询缴存金额收入总帐明细列表-月报")
	public AjaxResult getMonthReport(GwjReportFinanceMoneyQueryRequest request) {
		if (StringUtils.isNull(request.getYear())) {
			return AjaxResult.error("年份不能为空");
		}
		return AjaxResult.success(financeMoneyService.getMonthReport(request));
	}
}
